﻿Imports System.Data
Imports System.Data.OracleClient
Imports System.Windows.Forms
Imports WindowsApplication1.funciones
Public Class CuentaCob
    'conexion para inicializar la barra del navegador
    Dim conexion As String = "Driver={Microsoft ODBC for Oracle};Server=xe;Uid=redes;Pwd=redes;"

    'query para el dgv
    Dim querydgv As String = " select * from TB_VNT_CUENTAS_COBRAR"

    'variables a incluir si van a llenar un combo
    Dim querycomboic As String = "select ID_FACTURA from TB_VNT_FACTURA"
    Dim valuecomboic As String = "ID_FACTURA"
    Dim displaycomic As String = "ID_FACTURA"
    Dim queryt As String = "select TOTAL from TB_VNT_FACTURA"
    Dim valuet As String = "TOTAL"
    Dim displayt As String = "TOTAL"

    Dim querysecuencia As String = "SELECT MAX(ID_CUENTA)+ 1 AS ID_CUENTA FROM TB_VNT_CUENTAS_COBRAR"
    Dim camposecuencia As String = "ID_CUENTA"

    Dim temp As String = traersecuencia(querysecuencia, camposecuencia)
 
    'variables para llenado del vector
    Dim sizevector As Integer = 4
    Dim vector(sizevector) As TextBox

    'variable para llevar la secuencia en el campo ID
    
    Public Function LlenarVector() As TextBox()
        vector(0) = txt_id_cuenta
        vector(1) = TextFechaCC
        vector(2) = txt_total
        vector(3) = txt_saldo
        vector(4) = TextIF

        Return vector
    End Function

    Private Sub CuentaporCobrar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        vector = LlenarVector()
        BarraNavegacion1.Inicializar(conexion, "TB_VNT_CUENTAS_COBRAR", vector)
        'para llevar la secuencia del codigo

        'para mostrar la fecha en el texbox en formato corto
        TextFechaCC.Text = Date.Today.ToShortDateString

        'llenado del combo
        llenarcombo(ComboIFCC, querycomboic, valuecomboic, displaycomic)

        'llenartext(TextSaldo, queryt, valuet, displayt)
        'llenado del datagridview
        DGVCuentaCobrar.DataSource = LlenarDgv(querydgv)

        'llenado del vector

        txt_id_cuenta.Text = temp

    End Sub
    Private Sub TextFechaCC_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextFechaCC.TextChanged
        If TextFechaCC.Text = "" Then
            TextFechaCC.Text = Date.Today.ToShortDateString
        End If
    End Sub
    Private Sub ComboIFCC_TextChange(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboIFCC.TextChanged

        If ComboIFCC.ValueMember.Any Then
            TextIF.Text = ComboIFCC.SelectedValue
        End If

    End Sub

    Private Sub ComboIFCC_EnabledChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        'MessageBox.Show("Se ha cambiado la propiedad enabled del texto1 a:" + TEXTO1.Enabled.ToString)

        txt_total.Enabled = ComboIFCC.Enabled.ToString
    End Sub

    Private Function ExecuteQuery(p1 As String) As DataSet
        Throw New NotImplementedException
    End Function

    Private Function GetItem(cctotal As DataSet, totalcc As String) As String
        Throw New NotImplementedException
    End Function

    Private Sub TextIF_TextChanged(sender As Object, e As System.EventArgs) Handles TextIF.TextChanged

        Try


            Dim querytext1 As String = " select TOTAL from TB_VNT_FACTURA  where ID_FACTURA =  " & Me.TextIF.Text & ""
            Dim query As String = "TOTAL"
            Dim campo As String = "TOTAL"
            llenarcombo(cmb_saldo, querytext1, query, campo)
            Dim querytext2 As String = " select C.MONTO from TB_VNT_ABONO C, TB_VNT_CUENTAS_COBRAR B, TB_VNT_FACTURA A where A.ID_FACTURA = " & Me.TextIF.Text & " "
            Dim query2 As String = "MONTO"
            Dim campo2 As String = "MONTO"
            llenarcombo(cmbtabono, querytext2, query2, campo2)
        Catch ex As Exception

        End Try
    End Sub


    Private Sub txt_abono_EnabledChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txt_abono.EnabledChanged
        cmb_saldo.Enabled = txt_abono.Enabled.ToString
        cmbtabono.Enabled = txt_abono.Enabled.ToString
        ComboIFCC.Enabled = txt_abono.Enabled.ToString



    End Sub

    Private Sub txt_saldo_EnabledChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txt_saldo.EnabledChanged

        If txt_saldo.Enabled = True Then

            txt_total.Enabled = False

        End If
    End Sub

   

    Private Sub txt_saldo_TextChanged(sender As Object, e As System.EventArgs) Handles txt_saldo.TextChanged
        Try
            Dim num1 As String = txt_abono.Text
            Dim num2 As String = txt_saldo.Text
            Dim resultado As String
            resultado = ((num2) - (num1))
            txt_total.Text = resultado
        Catch
        End Try
    End Sub

    Private Sub cmb_saldo_TextChanged(sender As Object, e As System.EventArgs) Handles cmb_saldo.TextChanged
        If cmb_saldo.ValueMember.Any Then
            txt_saldo.Text = cmb_saldo.SelectedValue
        End If
    End Sub

    Private Sub cmbtabono_TextChanged(sender As Object, e As System.EventArgs) Handles cmbtabono.TextChanged
        If cmbtabono.ValueMember.Any Then
            txt_abono.Text = cmbtabono.SelectedValue
        End If
    End Sub

    Private Sub txt_id_cuenta_EnabledChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txt_id_cuenta.EnabledChanged
        If txt_id_cuenta.Enabled = True Then
            txt_id_cuenta.Enabled = False
            ComboIFCC.Enabled = True
        End If
    End Sub

    Private Sub txt_id_cuenta_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txt_id_cuenta.TextChanged
        If txt_id_cuenta.Text = "" Then
            Dim querysecuencia2 As String = "SELECT MAX(ID_CUENTA)+ 1 AS ID_CUENTA FROM TB_VNT_CUENTAS_COBRAR"
            Dim camposecuencia2 As String = "ID_CUENTA"
            Dim temp As String = traersecuencia(querysecuencia2, camposecuencia2)
            txt_id_cuenta.Text = temp
            cmb_saldo.Text = ""
            cmbtabono.Text = ""
            ComboIFCC.Text = ""

        End If
    End Sub

    Private Sub btn_actualiza_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_actualiza.Click
        DGVCuentaCobrar.DataSource = LlenarDgv(querydgv)
    End Sub
End Class